package design.simdi.code.final_paper.site.panels.sesiuni;

import java.text.SimpleDateFormat;

import org.apache.wicket.Page;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.form.AjaxFallbackButton;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.basic.MultiLineLabel;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;

import design.simdi.code.final_paper.core.entities.Sesiune;
import design.simdi.code.final_paper.site.panels.PagePanel;

/**
 * 
 * @author Marius Dumitriu - (Jun 24, 2010 - 12:28:00 AM)
 * 
 */
public class ViewSesiuneDetails extends PagePanel {

	private static final long serialVersionUID = 1L;
	private Sesiune sesiune;

	private Label name;
	private MultiLineLabel description;
	private AjaxFallbackButton back;
	@SuppressWarnings("unchecked")
	private Form form;

	public ViewSesiuneDetails(String id, IModel<Sesiune> model) {
		super(id, model);

	}

	@SuppressWarnings("unchecked")
	@Override
	public void panelInit() {
		setOutputMarkupId(true);

		sesiune = (Sesiune) getDefaultModelObject();

		form = new Form("form");
		SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
		form.add(name = new Label("name", sesiune.getName() + " (" + sdf.format(sesiune.getDataStart()) + " - "
				+ sdf.format(sesiune.getDataStop()) + ")"));
		form.add(description = new MultiLineLabel("description", new PropertyModel<String>(sesiune, "description")));

		name.setEnabled(false);
		description.setEnabled(false);

		add(form);
		back = new AjaxFallbackButton("cancel", form) {

			private static final long serialVersionUID = 1L;

			@Override
			protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
				InscriereTabPanel panel = new InscriereTabPanel("panel");
				panel.setOutputMarkupId(true);

				Page page = this.getPage();

				page.get("content:tabs:panel").replaceWith(panel);

				target.addComponent(page);
			}
		};
		form.add(back);

	}
}
